textArea.with{
    text = text.replaceAll(/\n\s+\{\n?/, "{\n").replaceAll(
        /( *\n){3,}/,
        "\n\n"
    )

    goToBufferStart(false)
    (getText().readLines().size() - 1).times{
        goToEndOfWhiteSpace(false)
        def lineLast = getText(caretPosition - 1 , 1)
        delete()
        insertEnterAndIndent()
        if( lineLast =~ /\(|\[/ )
            shiftIndentRight()
        if( getText(caretPosition , 1) =~ /\)|\]/ )
            shiftIndentLeft()
    }
    
    def startCase = false
    text = text.readLines().collect{
        def line = it
        
        if( it =~ /^\s*(case\s+.+|default):$/ ){
            startCase = true
        } else if( startCase ){
            line = "    " + it
        }
        
        if( it =~ /^\s*break\s*$/ )
            startCase = false
        
        line
    }.join("\n")
}
